#pragma once

#include <string.h>

#include <algorithm>
#include <list>
#include <map>
#include <mutex>
#include <string>

#include "bondlib.h"

class S_BONDLIB_EXPORT CExchangeRepoUnit {
 public:
  char RateKey[16];      // 键值
  char ID[8];            // ID
  char Code[8];          // 代码
  char Name[64];         // 名称
  char ListedMarket[8];  // 所在市场

  const bool operator<(const CExchangeRepoUnit& one) const {
    return strcmp(RateKey, one.RateKey) < 0;
  }
  const bool operator==(const CExchangeRepoUnit& one) {
    return strcmp(RateKey, one.RateKey) == 0;
  }
};

class CExchangeRepoInfo_Impl;
class S_BONDLIB_EXPORT CExchangeRepoInfo {
 public:
  static CExchangeRepoInfo& instance();

 public:
  const CExchangeRepoUnit* GetItem(const char* strID);

  void Clear();
  void Add(CExchangeRepoUnit& one);
  int GetSize();

  std::mutex* GetMutex();
  std::map<std::string, CExchangeRepoUnit>* GetData();

 public:
  void DumpStatus(int mode = 0) const;

 private:
  CExchangeRepoInfo();
  virtual ~CExchangeRepoInfo();

 private:
  CExchangeRepoInfo_Impl* m_impl;
};
